package com.brandon.HuntedRPG.activity;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.brandon.HuntedRPG.HuntedRPGApplication;
import com.brandon.HuntedRPG.R;
import com.brandon.HuntedRPG.context.WorldContext;
import com.brandon.HuntedRPG.model.ability.ActorConditionType;
import com.brandon.HuntedRPG.view.AbilityModifierInfoView;
import com.brandon.HuntedRPG.view.ItemEffectsView_OnUse;

public class ActorConditionInfoActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		HuntedRPGApplication app = HuntedRPGApplication.getApplicationFromActivity(this);
		if (!app.isInitialized()) {
			finish();
			return;
		}
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		final WorldContext world = app.world;

		String conditionTypeID = getIntent().getData().getLastPathSegment().toString();
		ActorConditionType conditionType = world.actorConditionsTypes.getActorConditionType(conditionTypeID);

		setContentView(R.layout.actorconditioninfo);

		TextView tv = (TextView) findViewById(R.id.actorconditioninfo_title);
		tv.setText(conditionType.name);
		world.tileManager.setImageViewTile(tv, conditionType);

		Button b = (Button) findViewById(R.id.actorconditioninfo_close);
		b.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				ActorConditionInfoActivity.this.finish();
			}
		});

		update(conditionType);
	}

	private void update(ActorConditionType conditionType) {
		final Resources res = getResources();
		LinearLayout lv;
		TextView tv;

		tv = (TextView) findViewById(R.id.actorconditioninfo_category);
		final String categoryName = res.getStringArray(R.array.actorcondition_categories)[conditionType.conditionCategory];
		tv.setText(res.getString(R.string.actorconditioninfo_category, categoryName));

		((AbilityModifierInfoView) findViewById(R.id.actorconditioninfo_constant_effect_abilitymodifierinfo)).update(
				conditionType.abilityEffect, false);

		tv = (TextView) findViewById(R.id.actorconditioninfo_constant_effect_title);
		if (conditionType.abilityEffect != null) {
			tv.setVisibility(View.VISIBLE);
		} else {
			tv.setVisibility(View.GONE);
		}

		tv = (TextView) findViewById(R.id.actorconditioninfo_everyround_title);
		if (conditionType.statsEffect_everyRound != null) {
			tv.setVisibility(View.VISIBLE);
			lv = (LinearLayout) findViewById(R.id.actorconditioninfo_everyround_list);
			ItemEffectsView_OnUse.describeStatsModifierTraits(conditionType.statsEffect_everyRound, this, res, lv);
		} else {
			tv.setVisibility(View.GONE);
		}

		tv = (TextView) findViewById(R.id.actorconditioninfo_everyfullround_title);
		if (conditionType.statsEffect_everyFullRound != null) {
			tv.setVisibility(View.VISIBLE);
			lv = (LinearLayout) findViewById(R.id.actorconditioninfo_everyfullround_list);
			ItemEffectsView_OnUse.describeStatsModifierTraits(conditionType.statsEffect_everyFullRound, this, res, lv);
		} else {
			tv.setVisibility(View.GONE);
		}
	}
}
